1   /*
2    * Copyright (C) 2009 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect;
18  
19  import java.util.Collection;
20  
21  import javax.annotation.Nullable;
22  
23  /**
24   * A GWT-only class only used by GWT emulations.  It is used to consolidate the
25   * definitions of method delegation to save code size.
26   *
27   * @author Hayward Chan
28   */
29  // TODO: Make this class GWT serializable.
30  class ForwardingImmutableCollection<E> extends ImmutableCollection<E> {
31  
32    transient final Collection<E> delegate;
33  
34    ForwardingImmutableCollection(Collection<E> delegate) {
35      this.delegate = delegate;
36    }
37  
38    @Override public UnmodifiableIterator<E> iterator() {
39      return Iterators.unmodifiableIterator(delegate.iterator());
40    }
41  
42    @Override public boolean contains(@Nullable Object object) {
43      return object != null && delegate.contains(object);
44    }
45  
46    @Override public boolean containsAll(Collection<?> targets) {
47      return delegate.containsAll(targets);
48    }
49  
50    public int size() {
51      return delegate.size();
52    }
53  
54    @Override public boolean isEmpty() {
55      return delegate.isEmpty();
56    }
57  
58    @Override public Object[] toArray() {
59      return delegate.toArray();
60    }
61  
62    @Override public <T> T[] toArray(T[] other) {
63      return delegate.toArray(other);
64    }
65  
66    @Override public String toString() {
67      return delegate.toString();
68    }
69  }